<?php

//class department
//{



     function worker(){
        $data = [
            0=>[
                'name'=>'测试',
                'id'=>'40',
                'pid'=>'0'
            ],
            1=>[
                'name'=>'运营',
                'id'=>'41',
                'pid'=>'0'
            ],
            2=>[
                'name'=>'测试小组1',
                'id'=>'42',
                'pid'=>'40'
            ],
            3=>[
                'name'=>'市场',
                'id'=>'44',
                'pid'=>'0'
            ],
            4=>[
                'name'=>'测试小组2',
                'id'=>'95',
                'pid'=>'40'
            ],
            5=>[
                'name'=>'小小组',
                'id'=>'120',
                'pid'=>'95'
            ],
            6=>[
                'name'=>'市场小组',
                'id'=>'100',
                'pid'=>'44'
            ],
            7=>[
                'name'=>'测试A',
                'id'=>'55',
                'pid'=>'0'
            ],
            8=>[
                'name'=>'测试B',
                'id'=>'66',
                'pid'=>'0'
            ],
            9=>[
                'name'=>'测试C',
                'id'=>'77',
                'pid'=>'0'
            ],
            10=>[
                'name'=>'测试D',
                'id'=>'88',
                'pid'=>'0'
            ],
        ];

        $depart = getTree($data);
        return $depart;
    }

     function getTree($data, $pid = 0)
    {
        global $html;
        //遍历部门
        foreach ($data as $key => $val) {
            //判断是否有子部门
            if ($val['pid'] == $pid) {
                $html .= '<dl>';
                $html .= '<dt class="allSelectCheck"><i class="icon-file"></i>' . $val['name'] . '<input type="checkbox" name="checkAlldpt10" value="' . $val['name'] . '"></dt>';

                $html .= '<dd>';
                $html = getTree($data, $val['id']);
                $html .= '</dd>';
                $html .= '</dl>';

            }
        }
        return $html;
    }

    $wooo = worker();
    print $wooo;





?>